//
//  NYMyConsumeRecordViewController.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/9.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYMyConsumeRecordViewController.h"
#import "NYMyConsumeRecordRequest.h"
#import "NYRefreshFooter.h"
@interface NYMyConsumeRecordViewController ()
@property(nonatomic, strong) NYMyConsumeRecordRequest *request;
@end

@implementation NYMyConsumeRecordViewController

#pragma mark - Life Cycle Methods

- (void)viewDidLoad {
        [super viewDidLoad];
        
        [self loadData];
}

- (void)loadData {
        
        [self setLoading:YES animation:YES];
        [self configNimbus];
        self.request = [NYMyConsumeRecordRequest requestWithParams:nil];
        
        @weakify(self);
        [[self.request pullDown] startWithSuccess:^(__kindof BaseRequest * _Nonnull request, __kindof NYMyConsumeRecordListModel * _Nonnull data) {
                
                @strongify(self);
                [self.tableViewModel addObjectsFromArray:data.order];
                [self.tableView reloadData];
                [self setSuccess];
        } failed:^(__kindof BaseRequest * _Nonnull request, NSError * _Nonnull error) {
                [self setError:error];
        }];
}
- (void)setSuccess {
        [super setSuccess];
        [self configRefreshFooter];
}
- (void)configRefreshFooter {
        
        @weakify(self);
        self.tableView.mj_footer = [NYRefreshFooter footerWithRefreshingBlock:^{
                @strongify(self);
                [[self.request pullUp] startWithSuccess:^(__kindof BaseRequest * _Nonnull request, __kindof NYMyConsumeRecordListModel * _Nonnull data) {
                        
                        [self.tableViewModel addObjectsFromArray:data.order];
                        [self.tableView reloadData];
                        [data.order count] == 0 ? [self.tableView.mj_footer endRefreshingWithNoMoreData] : [self.tableView.mj_footer endRefreshing];
                } failed:^(__kindof BaseRequest * _Nonnull request, NSError * _Nonnull error) {
                        
                        [self.tableView.mj_footer endRefreshingWithNoMoreData];
                }];
        }];
}

- (void)configNavigationBar:(BaseNavigationBar *)navigationBar {
        [super configNavigationBar:navigationBar];
        self.title = @"消费记录";
}
+ (NYViewControllerNavigationBarType)navigationBarType {
        
        return NYViewControllerNavigationBarTypeBlue;
}

@end
